package com.js.purs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.js.purs.domain.PurBindExpert;
import com.js.purs.service.IPurBindExpertService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 招标专家关联Controller
 * 
 * @author lzq
 * @date 20240704
 */
@RestController
@RequestMapping("/bindExpert")
public class PurBindExpertController extends BaseController
{
    @Autowired
    private IPurBindExpertService purBindExpertService;

    /**
     * 查询招标专家关联列表
     */
    @RequiresPermissions("purs:bindExpert:list")
    @GetMapping("/list")
    public TableDataInfo list(PurBindExpert purBindExpert)
    {
        startPage();
        List<PurBindExpert> list = purBindExpertService.selectPurBindExpertList(purBindExpert);
        return getDataTable(list);
    }

    /**
     * 导出招标专家关联列表
     */
    @RequiresPermissions("purs:bindExpert:export")
    @Log(title = "招标专家关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurBindExpert purBindExpert)
    {
        List<PurBindExpert> list = purBindExpertService.selectPurBindExpertList(purBindExpert);
        ExcelUtil<PurBindExpert> util = new ExcelUtil<PurBindExpert>(PurBindExpert.class);
        util.exportExcel(response, list, "招标专家关联数据");
    }

    /**
     * 获取招标专家关联详细信息
     */
    @RequiresPermissions("purs:bindExpert:query")
    @GetMapping(value = "/{bindExpertId}")
    public AjaxResult getInfo(@PathVariable("bindExpertId") Long bindExpertId)
    {
        return success(purBindExpertService.selectPurBindExpertByBindExpertId(bindExpertId));
    }

    /**
     * 新增招标专家关联
     */
    @RequiresPermissions("purs:bindExpert:add")
    @Log(title = "招标专家关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<PurBindExpert> purBindExpert)
    {
        return toAjax(purBindExpertService.insertPurBindExpert(purBindExpert));
    }

    @PostMapping("/insertBindExpert")
    public AjaxResult insertBindExpertSingle(@RequestBody PurBindExpert purBindExpert)
    {
        return toAjax(purBindExpertService.insertBindExpertSingle(purBindExpert));
    }

    /**
     * 修改招标专家关联
     */
    @RequiresPermissions("purs:bindExpert:edit")
    @Log(title = "招标专家关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurBindExpert purBindExpert)
    {
        return toAjax(purBindExpertService.updatePurBindExpert(purBindExpert));
    }

    /**
     * 删除招标专家关联
     */
    @RequiresPermissions("purs:bindExpert:remove")
    @Log(title = "招标专家关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bindExpertIds}")
    public AjaxResult remove(@PathVariable Long[] bindExpertIds)
    {
        return toAjax(purBindExpertService.deletePurBindExpertByBindExpertIds(bindExpertIds));
    }

    @GetMapping("/delBindExpertByExpertCode/{expertCode}")
    public AjaxResult delBindExpertByExpertCode(@PathVariable("expertCode") String expertCode)
    {
        return toAjax(purBindExpertService.deletePurBindExpertByExpertCode(expertCode));
    }

    @DeleteMapping("/delExpertBatch/{codeBatch}")
    public AjaxResult delExpertBatch(@PathVariable("codeBatch") String [] codeBatch){
        return success(purBindExpertService.delExpertBatch(codeBatch));
    }

    //初始化状态
    @DeleteMapping("/clearExpertByBindCode/{bindCode}")
    public AjaxResult clearExpertByBindCode(@PathVariable("bindCode") String  bindCode){
        return success(purBindExpertService.clearExpertByBindCode(bindCode));
    }
}
